// merchant//alliance/checkMoney/index.js
const app = getApp();
const utils = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    allianceId: 0,
    list: [],
    CurrentPage: 1,
    loadingMoreHidden: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.allianceId) {
      this.getcheckList(options.allianceId);
      this.setData({
        allianceId: options.allianceId
      })
    }
  },
  getcheckList: function (allianceId) {
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/alliance/GetCheckList?allianceid=' + allianceId + '&page=' + that.data.CurrentPage,
      success: function (res) {
        if (res.data.Code == 0) {
          let list = res.data.Data.Items;
          if(list.length>0){
            if (that.data.CurrentPage != 1) {
              var preGoods = that.data.list;
              list = preGoods.concat(list);
            }
            for(let i = 0; i < list.length; i++){
              list[i].Avatar = utils.formatAvater(list[i].Avatar, 'https://static.711688.net.cn/upload/card/source/');
              list[i].Date = list[i].CreateTime.substr(0,10);
              list[i].time = list[i].CreateTime.substr(11,8);
            }
            that.setData({
              list: list,
              loadingMoreHidden: res.data.Data.TotalPages
            })
          }
          
        }

      }
    })
  },
  loadMore: function(){
    var that = this;
    if (that.data.loadingMoreHidden > 1 && that.data.CurrentPage < that.data.loadingMoreHidden) {
      var currPage = that.data.CurrentPage;
      that.setData({
        CurrentPage: currPage + 1
      })
      that.getcheckList(that.data.allianceId);
    } else {
      return
    }
  },

  toDetail: function(e){
    let cid = e.currentTarget.dataset.cid;
    wx.navigateTo({
      url: '../checkDetail/index?cid=' + cid,
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.loadMore();
  }
})